<?php


/**
* Sends the website inquiry messages to the administrators
*/

if($variable->post('submit_button', 'string', ''))
{
	#die('Replace CONTACTUS_EMAILTEMPLATE, CONTACTUS_SENDERSMTP, CONTACTUS_ADMINEMAIL, CONTACTUS_ADMINNAME : '.__FILE__.', '.__LINE__); # use the proper template ID
	$defines = array(
		'CONTACTUS_EMAILTEMPLATE',
		'CONTACTUS_SENDERSMTP',
		'CONTACTUS_ADMINEMAIL',
		'CONTACTUS_ADMINNAME',
	);
	foreach($defines as $d => $define) if(!defined($define)) die('Contact Us definition parameters missing.');
	$email_template = new email_template(CONTACTUS_EMAILTEMPLATE);
	$sender = new sender(CONTACTUS_SENDERSMTP);
	$sender->ClearAddresses();
	
	# Send email to the administrator
	$sender->add_recipient(new datatype_recipient(CONTACTUS_ADMINEMAIL, CONTACTUS_ADMINNAME));
	
	# Replies back to the messenger
	$sender->AddReplyto($variable->post('email', 'string', ''), $variable->post('name', 'string', ''));
	
	$data = array(
		'NAME' => $variable->post('name', 'string', ''),
		'EMAIL' => $variable->post('email', 'string', ''),
		'SUBJECT' => $variable->post('subject', 'string', ''),
		'MESSAGE' => $variable->post('message', 'string', '')	
	);
	$template_data = $email_template->read_template($data);
	$success = $sender->deliver($template_data);
	
	$messenger = new messenger('success', 'Your inquiry has been successfully forwarded to the administrator. Please wait for the response.');
	
	stopper::url('./');
}
?>